package com.taotao.merchant.controller;

import com.github.pagehelper.PageInfo;
import com.taotao.common.core.domain.Result;
import com.taotao.merchant.annotation.Idempotent;
import com.taotao.merchant.domain.Coupon;
import com.taotao.merchant.domain.SkuInfo;
import com.taotao.merchant.domain.request.CouponRequest;
import com.taotao.merchant.domain.request.CouponSearchRequest;
import com.taotao.merchant.domain.response.CouponResponse;
import com.taotao.merchant.service.CouponService;
import com.taotao.merchant.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.RequestData;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;


/**
 * @className: CouponController
 * @author: ZhangYuQi
 * @date: 2025/1/13 下午12:13
 * @Version: 1.0
 * @description:
 */

@RestController
    @RequestMapping("coupon")
public class CouponController {

    @Autowired
    private CouponService couponService;

    @Autowired
    private TokenService tokenService;


    /**
    * @Author ZhangYuQi
    * @Description 查询商户发放的优惠券列表
    * @Date 下午6:44 2025/1/13
    * @Param []
    * @return
    */
    @GetMapping("getCoupons")
    public Result<PageInfo<Coupon>> getCoupons(CouponSearchRequest coupon) {
        return Result.success(couponService.getCoupons(coupon));
    }


    /**
    * @Author ZhangYuQi
    * @Description 根据优惠券id查询优惠券详情信息
    * @Date 下午7:35 2025/1/13
    * @Param [id]
    * @return
    */
    @GetMapping("getCouponById/{id}")
    public Result<CouponResponse> getCouponById(@PathVariable Long id) {
        return Result.success(couponService.getCouponById(id));
    }


    /**
    * @Author ZhangYuQi
    * @Description 逻辑删除优惠券
    * @Date 下午8:31 2025/1/13
    * @Param [id]
    * @return
    */
    @PutMapping("delCouponById/{id}")
    public Result delCouponById(@PathVariable Long id) {
        couponService.delCouponById(id);
        return Result.success();
    }

    /**
    * @Author ZhangYuQi
    * @Description 添加优惠券
    * @Date 下午10:15 2025/1/13
    * @Param [couponRequest]

     * @return
    */
    @PostMapping("addCoupon")
    @Idempotent(name = "requestData", type = RequestData.class, field = "token")
    public Result addCoupon(@RequestBody CouponRequest couponRequest) throws ParseException {

       couponService.addCoupon(couponRequest);
        return Result.success();
    }

    /**
    * @Author ZhangYuQi
    * @Description 获取当前登录商户所有sku商品
    * @Date 下午8:30 2025/1/14
    * @Param []
    * @return
    */
    @GetMapping("getSkuList")
    public Result<List<SkuInfo>> getSkuList() {
        return Result.success(couponService.getSkuList());
    }


}
